<?php
/**
 * common repository file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2020/04/24
 * Time: 15:16
 */

namespace HiCommon\Repository;

use Illuminate\Support\Facades\DB;

class ViewFinanceOrderRefundRepository extends BaseRepository
{

    public function base_model()
    {
        return new \HiCommon\Model\ViewFinanceOrderRefund();
    }

    public function order_sum_refund_price($arr_search = [], $arr_where = [], $arr_wherein = [])
    {
        $n_pay_ratio = common_pay_ratio();

        $arr_date      = format_date($arr_search);
        $arr_between   = $arr_date['date_between'];
        $s_date_format = $arr_date['date_format'];
        $arr_select    = [DB::raw('date_format(created_at,"' . $s_date_format . '") as date'), DB::raw('sum(refund_fee)*'.$n_pay_ratio.' as sum_refund_fee')];
        $res           = self::base_model()
                             ->where($arr_where)
                             ->basicWherein($arr_wherein)
                             ->where(
                               function ($query)
                               use ($arr_search) {
                                   $n_shop_id = intval($arr_search['shop_id']);
                                   if ($n_shop_id > 0) {
                                       $query->where('shop_id', $n_shop_id);
                                   }
                               }
                             )
                             ->whereBetween('created_at', $arr_between)
                             ->groupBy('date')
                             ->orderBy('date', 'desc')
                             ->get($arr_select);
        return $res;
    }

    /***************************************************** 平台 *****************************************************/
    /*平台-指定日期-总退款*/
    public function platform_order_sum_refund_price($arr_search)
    {
        return self::order_sum_refund_price($arr_search);
    }

    /***************************************************** 检测机构 *****************************************************/
    /*检测机构-年检预约单-指定日期总退款*/
    public function jc_njyy_order_sum_refund_price($arr_search)
    {
        $arr_where = ['order_type' => 'njyy'];
        return self::order_sum_refund_price($arr_search, $arr_where);
    }

    /***************************************************** 维修店 *****************************************************/
    /*维修店-指定日期总退款*/
    public function weixiu_order_sum_refund_price($arr_search,$arr_where = [])
    {
        $arr_wherein = ['order_type' => ['ptshp','wxfw','wxby']];
        return self::order_sum_refund_price($arr_search, $arr_where,$arr_wherein);
    }

}